<template>
    <div>
        <Card>
            <p slot="title"> 操作日志 </p>
            <Table stripe :loading="loading" :columns="columns1" :data="data1"></Table>
            <Page show-total show-sizer :total=total :current="search.page" :page-size="search.rows" @on-page-size-change="getListByPageSize" @on-change="getListByPageNum" />
        </Card>
    </div>
</template>
<script>
    import axios from '@/libs/api.request'
    export default {
        name: 'handle-log',
        data() {
            return {
                loading: false,

                // 总条数
                total: 0,

                search: {
                    page: 1,
                    rows: 10
                },

                columns1: [{
                        type: 'index',
                        width: 50,
                        align: 'center'
                    },
                    {
                        title: '操作用户',
                        align: 'center',
                        key: 'username'
                    },
                    {
                        title: '操作IP',
                        align: 'center',
                        key: 'ip'
                    },
                    {
                        title: '请求地址',
                        align: 'center',
                        key: 'request_url'
                    },
                    {
                        title: '描述',
                        align: 'center',
                        key: 'controller_action_desc'
                    },
                    {
                        title: '请求方法',
                        align: 'center',
                        key: 'method'
                    },
                    {
                        title: '请求参数',
                        align: 'center',
                        key: 'params'
                    },
                    {
                        title: '请求结果',
                        align: 'center',
                        key: 'result'
                    },
                    {
                        title: '操作时间',
                        align: 'center',
                        key: 'c_time'
                    }
                ],
                data1: []
            }
        },
        methods: {
            // 获取日志列表
            getList() {
                this.loading = true
                let {
                    ...data
                } = this.search
                axios.ajax_post('admin-admin_operate-ajax_get_ao', data).then(response => {
                    this.loading = false
                    if (response.data.code === 1) {
                        this.total = response.data.data.total_num
                        this.data1 = response.data.data.list

                        if (this.data1.length < 1 && this.total > 0) {
                            this.search.page = Math.ceil(this.total / this.search.rows)
                            this.getList()
                        }
                    } else {
                        this.$Notice.error({
                            title: response.data.msg,
                            duration: 3
                        })
                    }
                })
            },

            getListByPageSize(rows) {
                this.search.rows = rows
                this.getList()
            },

            getListByPageNum(page) {
                this.search.page = page
                this.getList()
            }
        },
        created() {
            this.getList()
        }
    }
</script>
<style lang="stylus" scoped>

</style>